package com.hl.sfzy.controller;

import com.hl.sfzy.constant.CommonConstant;
import com.hl.sfzy.constant.Result;
import com.hl.sfzy.entity.SysReply;
import com.hl.sfzy.entity.SysUser;
import com.hl.sfzy.service.SysReplyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @author ffc
 * @version 1.0
 * @description: TODO
 * @className: SysReplyController
 * @date 2024/7/12 17:07
 */

@RestController
public class SysReplyController {

    @Autowired
    private SysReplyService sysReplyService;

    /*新增回复*/
    @PostMapping("/sysreply")
    public Result add(@RequestBody SysReply sysReply){
        return sysReplyService.add(sysReply)>0?Result.success():Result.error() ;
    }

    /*根据id删除回复*/
    @DeleteMapping("/sysreply/{id}")
    public Result remove(@PathVariable("id") Integer id){
        return sysReplyService.remove(id)>0?Result.success():Result.error() ;
    }

    /*根据id批量删除回复*/
    @DeleteMapping("/sysreply")
    public Result removeBatch(Integer[] ids){
        return sysReplyService.removeBatch(ids)>0?Result.success():Result.error();
    }


    /*根据id查找回复*/
    @GetMapping("/sysreply/{id}")
    public Result findById(@PathVariable Integer id){
        SysReply sysReply = sysReplyService.findById(id);
        return Result.success(sysReply);
    }

    /*查找全部回复*/
    @GetMapping("/sysreply")
    public Result find(SysReply sysReply){
        List<SysReply> list = sysReplyService.find(sysReply);
        return Result.success(list);
    }

    /*根据分页查询回复*/
    @GetMapping("/sysreply/page")
    public Result findPage(
            @RequestParam(value = CommonConstant.PAGE_NUM,required = false,defaultValue = CommonConstant.PAGE_NUM_DEFAULT) Integer pageNum,
            @RequestParam(value = CommonConstant.PAGE_SIZE,required = false,defaultValue = CommonConstant.PAGE_SIZE_DEFAULT) Integer pageSize,
            SysReply sysReply){
        Map<String, Object> map = sysReplyService.findPage(pageNum,pageSize,sysReply);
        return Result.success(map);
    }

}
